package com.zz.framework.core.ext

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE

/**
 * Copyright © 2022 StariverPool All rights reserved.
 * Created on 2022/4/26 15:01.
 * @version: V1.0
 */

fun RecyclerView.isScrollToBottom():Boolean{
    val layoutManager = layoutManager as? LinearLayoutManager ?: return false
    //屏幕中最后一个可见子项的position
    val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
    //当前屏幕所看到的子项个数
    val visibleItemCount = layoutManager.childCount;
    //当前RecyclerView的所有子项个数
    val totalItemCount = layoutManager.itemCount;
    //RecyclerView的滑动状态
    val state = scrollState;
    return visibleItemCount > 0 && lastVisibleItemPosition == totalItemCount - 1 && state == SCROLL_STATE_IDLE
}